﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FineUI;
using Maticsoft.BLL;
using Maticsoft.Model;

namespace FineUI.Examples
{
    public partial class teacher_update_perInformation : System.Web.UI.Page
    {

        protected void LoadTeacherInforamtion()
        {
            string currentT_Id = Session["UserName"].ToString();
            Maticsoft.BLL.Teacher TC = new Maticsoft.BLL.Teacher();
            Maticsoft.Model.Teacher TCInform = TC.GetModel(currentT_Id);

            tbxUserName.Text = TCInform.T_Id;
            tbxPassword.Text=TCInform.T_Password;
            tbxName.Text=TCInform.T_Name;
            tbxSex.Text=TCInform.T_Sex;
            tbxDepartment.Text=TCInform.T_Department;
            tbxDuty.Text=TCInform.T_Duty;
            tbxConnect.Text=TCInform.T_Contact;
            tbxEmail.Text=TCInform.T_Email;
        
        
        }

        protected void ExistsPermiss(string P_Id, string P_Status)
        {
            Maticsoft.BLL.Permissions PM = new Maticsoft.BLL.Permissions();
            if (!PM.ExistsPermiss(P_Id, P_Status))
            {
                Response.Redirect("~/user_no_permission.aspx");
            }

        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserName"] == null)
            {
                Response.Redirect("~/login.aspx");
                return;
            }
            ExistsPermiss("T000", "已授权");
            if(!IsPostBack)
            {
                LoadTeacherInforamtion();
            }
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            string currentT_Id = tbxUserName.Text.ToString();
            string currentT_Password = tbxPassword.Text.ToString();
            string currentT_Name = tbxName.Text.ToString();
            string currentT_Sex = tbxSex.Text.ToString();
            string currentT_Department = tbxDepartment.Text.ToString();
            string currentT_Duty = tbxDuty.Text.ToString();
            string currentT_Contact = tbxConnect.Text.ToString();
            string currentT_Email = tbxEmail.Text.ToString();

            Maticsoft.BLL.Teacher TC = new Maticsoft.BLL.Teacher();
            Maticsoft.Model.Teacher TCInform = TC.GetModel(currentT_Id);
            TCInform.T_Password = currentT_Password;
            TCInform.T_Name = currentT_Name;
            TCInform.T_Sex = currentT_Sex;
            TCInform.T_Department = currentT_Department;
            TCInform.T_Duty = currentT_Duty;
            TCInform.T_Contact = currentT_Contact;
            TCInform.T_Email = currentT_Email;

            if (!TC.Update(TCInform))
            {
                Alert.ShowInTop("修改信息失败！", MessageBoxIcon.Information);
            }
            else
                Alert.ShowInTop("修改信息成功！", MessageBoxIcon.Information);
            LoadTeacherInforamtion();
        }
    }
}